function varargout = ImpedanceGUI(varargin)
% IMPEDANCEGUI MATLAB code for ImpedanceGUI.fig
%      IMPEDANCEGUI, by itself, creates a new IMPEDANCEGUI or raises the existing
%      singleton*.
%
%      H = IMPEDANCEGUI returns the handle to a new IMPEDANCEGUI or the handle to
%      the existing singleton*.
%
%      IMPEDANCEGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IMPEDANCEGUI.M with the given input arguments.
%
%      IMPEDANCEGUI('Property','Value',...) creates a new IMPEDANCEGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ImpedanceGUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ImpedanceGUI_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help ImpedanceGUI

% Last Modified by GUIDE v2.5 03-Feb-2017 14:50:47

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ImpedanceGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @ImpedanceGUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before ImpedanceGUI is made visible.
function ImpedanceGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to ImpedanceGUI (see VARARGIN)

% Choose default command line output for ImpedanceGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

%enable axes interactivity
set(hObject, 'Toolbar', 'figure')

%Call script to create tabs in GUI
makeTabGroup

%turn off input axis labels and set instruction text
resetInputAxes
set(handles.text21, 'String', strcat('Please specify required fields,', ...
    ' then press the button corresponding to the desired infomation'));


% UIWAIT makes ImpedanceGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = ImpedanceGUI_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

setappdata(0, 'yamlFilePath', get(handles.edit5, 'String'))
set(handles.text17, 'String', 'Status: Working...')

%Process user inputs for use when running the code, and sets variables to
%be passed into the code
processInputs

%Run pressure portion of code
try
    [ P_Harmonics, t, ydata, z1, y, Yfft, delta_t, L, Tp ] = PressureOnlyFunc( SaveLocation, ...
        InputFilesLocation, instructionText, FileTypeInput, uploadFlag );
catch ME
    set(handles.text17, 'String', 'Status: Error. See command window for error details')
    set(handles.text21, 'String', strcat('Please specify required fields,', ...
        ' then press the button corresponding to the desired infomation'));
    resetInputAxes
    return
end

%plot pressure frequency data and waveform (time domain) data
pressurePlot

set(handles.text17, 'String', 'Status: Program complete. Use side tabs to view results.')
set(handles.text21, 'String', strcat('Please specify required fields,', ...
    ' then press the button corresponding to the desired infomation'));
resetInputAxes


% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton17 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.text17, 'String', 'Status: Working...')
setappdata(0, 'yamlFilePath', get(handles.edit5, 'String'))

%Process user inputs for use when running the code, and sets variables to
%be passed into the code
processInputs

%run flow portion of code
try
    [ F_Harmonics, t, ydata, z1, y, Yfft, delta_t, L, Tp ] = FlowOnlyFunc(inputAxes, ...
        SaveLocation, InputFilesLocation, instructionText, EchoTypeNum, uploadFlag );
catch ME
    set(handles.text17, 'String', 'Status: Error. See command window for error details')
    set(handles.text21, 'String', strcat('Please specify required fields,', ...
        ' then press the button corresponding to the desired infomation'));
    resetInputAxes
    return
end

%plot flow frequency data and waveform (time domain) data
flowPlot

set(handles.text17, 'String', 'Status: Program complete. Use side tabs to view results.')
set(handles.text21, 'String', strcat('Please specify required fields,', ...
    ' then press the button corresponding to the desired infomation'));
resetInputAxes



% --- Executes on button press in pushbutton18.
function pushbutton18_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton18 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.text17, 'String', 'Status: Working...')
setappdata(0, 'yamlFilePath', get(handles.edit5, 'String'))

%Process user inputs for use when running the code, and sets variables to
%be passed into the code
processInputs

%run full code
try
    [ F_Harmonics, P_Harmonics, t, ydata, z1, y, Yfft, delta_t, L, Tp, ...
        t_P, ydata_P, z1_P, y_P, Yfft_P, delta_t_P, L_P, Tp_P, Pressure, Flow, Impedence ] ...
        = ImpedanceOnlyFunc( inputAxes, SaveLocation, InputFilesLocation, instructionText, ...
        FileTypeInput, percentErrorText, P_ejectionDurationText, F_ejectionDurationText, ...
        uploadFlag, EchoTypeNum );
catch ME
    set(handles.text17, 'String', 'Status: Error. See command window for error details')
    set(handles.text21, 'String', strcat('Please specify required fields,', ...
        ' then press the button corresponding to the desired infomation'));
    resetInputAxes
    disp(getReport(ME,'extended'))
    return
end

%plot pressure frequency data and waveform (time domain) data
pressurePlotAlt %this script uses different input vars from pressurePlot but does the same thing

%plot flow frequency data and waveform (time domain) data
flowPlot

%Plot impedance data and pressure flow overlay
impedancePlot

set(handles.text17, 'String', 'Status: Program complete. Use side tabs to view results.')
set(handles.text21, 'String', strcat('Please specify required fields,', ...
    ' then press the button corresponding to the desired infomation'));
resetInputAxes








% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton2


% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton3


% --- Executes on button press in pushbutton25.
function pushbutton25_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton25 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
SaveLocation = uigetdir('Select Location for Saving of Graphics');
set(handles.edit4, 'String', SaveLocation);
handles.SaveLocation = get(handles.edit4, 'String');
guidata(hObject,handles);


% --- Executes on button press in pushbutton26.
function pushbutton26_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton26 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
InputFilesLocation = uigetdir('Select Location of Input Data Files');
set(handles.edit3, 'String', InputFilesLocation);
handles.InputFilesLocation = get(handles.edit3, 'String');
guidata(hObject,handles);




function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton27.
function pushbutton27_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton27 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.edit3, 'String', 'File path');
set(handles.edit4, 'String', 'File path');
set(handles.radiobutton2,'Value', 0);
set(handles.radiobutton3,'Value', 0);
set(handles.radiobutton4,'Value', 0);
set(handles.checkbox1,'Value', 0);
set(handles.jpegButton,'Value', 0);
set(handles.dicomButton,'Value', 0);
set(handles.text21, 'String', strcat('Please specify required fields,', ...
    ' then press the button corresponding to the desired infomation'));



% --- Executes on button press in pushbutton28.
function pushbutton28_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton28 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla(handles.axes13,'reset');cla(handles.axes15,'reset');cla(handles.axes16,'reset')
cla(handles.axes17,'reset');cla(handles.axes18,'reset');cla(handles.axes19,'reset')
cla(handles.axes20,'reset');
resetInputAxes




% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton4


% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox1


% --- Executes on button press in jpegButton.
function jpegButton_Callback(hObject, eventdata, handles)
% hObject    handle to jpegButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of jpegButton


% --- Executes on button press in dicomButton.
function dicomButton_Callback(hObject, eventdata, handles)
% hObject    handle to dicomButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of dicomButton


% --- Executes on button press in pushbutton29.
function pushbutton29_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton29 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
yamlPath = getFilePath('*.yaml', 'yaml');
set(handles.edit5, 'String', yamlPath);
%handles.InputFilesLocation = get(handles.edit5, 'String');
%guidata(hObject,handles);



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes when figure1 is resized.
function figure1_SizeChangedFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
